package day0408;

/**
 * @Author Weton Li
 * @Date 2021/4/8 16:30
 */
public class SingleTon1 {
    private SingleTon1() {

    }

    private volatile static SingleTon1 instance = null;

    public static SingleTon1 getInstance() {
        if (instance == null) {
            synchronized (SingleTon1.class) {
                if (instance == null) {
                    instance = new SingleTon1();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        SingleTon1 instance1 = getInstance();
        SingleTon1 instance2 = getInstance();

        if (instance1 == instance2) {
            System.out.println("相同");
        }
        System.out.println(instance1);
        System.out.println(instance2);


    }
}
